#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include "ui_mainwindow.h"
#include "interface.h"

namespace Ui {
    class MainWindow;
}

class QSqlDatabase;
class QSqlTableModel;
class QSqlRelationalTableModel;

class HeaderView;
class QGraphicsScene;

class MainWindow : public QMainWindow, private Ui::MainWindow
{
    Q_OBJECT
    
public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();

public slots:
    void currentChanged() { updateActions(); }
    void on_actionNew_triggered(){ addRequest(); }
    void on_actionEdit_triggered(){ editRequest(); }
    void on_actionDelete_triggered(){ deleteRequest(); }

protected:
    void closeEvent(QCloseEvent *event);
    void wheelEvent(QWheelEvent * event);

private slots:
    void about();
    void addRequest();
    void editRequest();
    void copyRequest();
    void deleteRequest();
    void updateActions();

    void showOperators();
    void showDepartments();
    void showItems();
    void showStores();
    void showOrganizations();

    void itemSelected(const QModelIndex& current, const QModelIndex& previous);
    void detailsSelected(const QModelIndex& current, const QModelIndex& previous);
    void activated(const QModelIndex &index);

    
    void on_actionOperators_triggered();

    void on_actionDepartments_triggered();

    void on_actionItems_triggered();

    void on_actionOpen_database_triggered() { openDatabase(); }

    void printPreview();
    void print(QPrinter* printer);
    void PDF();

    void zoom(const int zoom=0);

    void on_actionStores_triggered();

    void on_actionNew_database_triggered();

    void on_actionLicensing_triggered();

    void on_actionOrganizations_triggered();

    void on_actionSettings_triggered();

    void on_actionCopy_triggered() { copyRequest(); }

    void on_search_pushButton_toggled(bool checked);

    void on_search_lineEdit_textChanged(const QString &arg1);

    void on_actionFilter_triggered(bool checked);

private:
    void drawRequest(QGraphicsScene* scene, bool print=false);
    void drawMultiLineRequest(const QModelIndex &index, QGraphicsScene* scene, qreal dx, qreal dy, bool print=false);
    void drawSingleLineRequest(const QModelIndex &index, QGraphicsScene* scene, qreal dx, qreal dy, bool print=false);
    bool dbconnect(const QString& fileName = QString::null);
    void setTable(const QString& table);
    void setDetailsTable(const QString& table);
    void setDetailsFilter(const QString& filter);
    //void setFilter(const QString& filter);
    void openDatabase();
    void saveSettings();
    void readSettings();
    bool isValidDatabase();
    void loadLicenseInfo();
    bool loadUpdatePlugin();
    void naFilter(QString &str);
    void setApproach();
    void setUserFilter();



    QSqlDatabase* db;
    QSqlRelationalTableModel* model;
    QSqlTableModel* details_model;

    HeaderView* headerView;
    QGraphicsScene* my_scene;

    UpdMgrInterface* updmgr;
};

#endif // MAINWINDOW_H
